package Callable;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

public class CallableTest {

    // callable 使用

    //  问题 线程调用的方式 3种  runnable  callable  线程池


    public static void main(String[] args) throws Exception {
//        callable 使用
        Callable<String> call = ()->{
            for (int i = 0; i < 20; i++) {
                System.out.println(Thread.currentThread().getName()+"i:"+i);
            }
            return "123";
        };

        new Thread(new FutureTask<>(
                call
        ),"1").start();
        new Thread(new FutureTask<>(
                call
        ),"1").start();

//        会堵塞
        System.out.println(call.call());
    }

}
